package com.example.st.controller;

import com.example.st.common.ResponseResult;
import com.example.st.entity.Info;
import com.example.st.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/infos")
public class InfoController {

    @Autowired
    private InfoService infoService;

    @GetMapping
    public ResponseResult<List<Info>> getAllInfos() {
        ResponseResult<List<Info>> response = infoService.getAllInfo();
        return response;
    }

    @GetMapping("/{id}")
    public ResponseResult<Info> getInfoById(@PathVariable("id") Long id) {
        ResponseResult<Info> response = infoService.getInfoById(id);
        return response;
    }

    @PostMapping
    public ResponseResult<Info> createInfo(@RequestBody Info info) {
        ResponseResult<Info> response = infoService.createInfo(info);
        return response;
    }

    @PutMapping("/{id}")
    public ResponseResult<Info> updateInfo(@PathVariable("id") Long id, @RequestBody Info infoDetails) {
        ResponseResult<Info> response = infoService.updateInfo(id, infoDetails);
        return response;
    }

    @PutMapping("/{id}/activate")
    public ResponseResult<Void> activateInfo(@PathVariable("id") Long id) {
        ResponseResult<Void> response = infoService.activateInfo(id);
        return response;
    }

    @PutMapping("/{id}/invalidate")
    public ResponseResult<Void> invalidateInfo(@PathVariable("id") Long id) {
        ResponseResult<Void> response = infoService.invalidateInfo(id);
        return response;
    }
}

